package com.app.server.impl;

import com.app.mapper.AdminUserMapper;
import com.app.mapper.UnitsDisasterMapper;
import com.app.mapper.UnitsManagerMapper;
import com.app.model.AdminUserModel;
import com.app.model.UnitsDisasterModel;
import com.app.model.UnitsManagerModel;
import com.app.server.UnitsDisasterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 单位管理和报灾管理的中间表
 */
@Service
public class UnitsDisasterServiceImpl extends ServiceImpl<UnitsDisasterMapper, UnitsDisasterModel> implements UnitsDisasterService {
    @Autowired
    private UnitsDisasterMapper unitsDisasterMapper;
    @Autowired
    private UnitsManagerMapper unitsManagerMapper;
    @Override
    public List<Integer> getDisasterCount() {
        List<Integer> disasterCount = unitsDisasterMapper.getDisasterCount();
        return disasterCount;
    }

    @Override
    public List<UnitsManagerModel> getByReportId(Integer id) {
        QueryWrapper<UnitsDisasterModel> unitsDisasterModelQueryWrapper = new QueryWrapper<>();
        unitsDisasterModelQueryWrapper.eq("disaster_id",id);
        List<UnitsDisasterModel> list = unitsDisasterMapper.selectList(unitsDisasterModelQueryWrapper);
        List<UnitsManagerModel> unitsManagerModels = new ArrayList<>();
        for (UnitsDisasterModel unitsDisasterModel : list) {
            UnitsManagerModel managerModel = unitsManagerMapper.selectById(unitsDisasterModel.getUnitsId());
            unitsManagerModels.add(managerModel);
        }
        return unitsManagerModels;
    }
}
